#include <iostream>
#include "observe_subject.h"
#include "observe.h"

using namespace std;

ObserveSubject::ObserveSubject()
{
    _obvl = new list<ObserveM*>;
}

ObserveSubject::~ObserveSubject()
{
    if(_obvl)
    {
        delete _obvl;
    }
}

void ObserveSubject::attatch(ObserveM *obv)
{
    _obvl->push_back(obv);
}

void ObserveSubject::detatch(ObserveM *obv)
{
    if(NULL != obv)
    {
        _obvl->remove(obv);
    }
}

void ObserveSubject::notify()
{
    list<ObserveM *>::iterator iter;

    iter = _obvl->begin();
    for(; iter != _obvl->end(); iter++)
    {
        (*iter)->update(this);
    }
}

//==========================================================
//ConcreteObvSubject
ConcreteObvSubject::ConcreteObvSubject()
{

}
ConcreteObvSubject::~ConcreteObvSubject()
{

}

State ConcreteObvSubject::GetState()
{
    return _st;
}

void ConcreteObvSubject::SetState(const State& st)
{
    _st = st;
}

